home *** CD-ROM | disk | FTP | other *** search
- 0 ' program = ---- KB_FLAG -----
- 1 'Author: Herb Shear, 1590 Vineyard Dr., Los Altos, CA 94022
- 2 'This program demonstrates the KB_FLAG at location 0000:0417
- 3 'By setting bits in the KB_FLAG byte you can effective press several
- 4 'of the keyboard keys from your program. When the program expects a
- 5 'numeric response have the program `press' NumLock so you can use the
- 6 'keypad without further ado.
- 7 'A typical statement to do that would be:
- 8 'DEF SEG=0:POKE &H417, PEEK(&H417) OR &H20
- 100 ' Now, as they say in Algol, leave us BEGIN
- 110 CLS: KEY OFF 'let's get a clean slate.
- 120 GOSUB 590 ' disable CtrlBrk since we will be pressing those keys.
- 130 DEF SEG = &H40 'there are more ways than cats.
- 140 DEFINT A-Z 'cause it's even slower without this.
- 150 '-------Read DATA words into string array------------------
- 160 FOR I = 7 TO 0 STEP -1
- 170 READ A$(I)
- 180 NEXT
- 190 '---Function to extract selected bit from an integer or a byte.--
- 200 ' The function must be introduced to the interpreter before it
- 210 ' can be called. So, Mr. FUNCTION, meet Mr. BASIC INTERPRETER.
- 220 DEF FNBITVALUE(BYTE,BIT) = BYTE \ 2^BIT MOD 2
- 230 '------Set up the fixed portion of the screen display--------
- 240 LOCATE 6,10,0:PRINT "The KB_FLAG controls the following functions:"
- 250 LOCATE 12,10: PRINT "The KB_FLAG bit pattern "+CHR$(26);
- 260 LOCATE 15,8:PRINT "DEF SEG=0: POKE 417, PEEK(417) AND &H OR &H";
- 270 LOCATE 17,4:PRINT "To determine AND value: Turn ON the items you really want to be OFF";
- 280 LOCATE 19,5:PRINT "To determine OR value: Turn ON the items you want to be ON.";
- 290 LOCATE 25,1: PRINT "Press ESC to exit"; 'Always nice to know.
- 300 PRINT " (but be brave and press some other keys first)";
- 310 POKE &H17,0 'just to start from the same value each RUN.
- 320 ' note that different segement (40 vs 0) requires a different
- 330 ' offset (17 vs 417). Segs left shift 4 bits (one hex digit)
- 340 ' before offset is added. Thus 0000:0417 = 0040:0017 = 0041:0007
- 350 ' and that still leaves 63 decimal cats unskinned.
- 360 '-------Start of display loop------------
- 370 FLAG = PEEK(&H17) 'fetch the current KB_FLAG byte.
- 380 LOCATE 12,38
- 390 '-------Extract and print each bit-----------
- 400 FOR I = 7 TO 0 STEP -1
- 410 PRINT USING "# "; FNBITVALUE(FLAG,I);
- 420 NEXT
- 430 LOCATE 15,55: PRINT USING "\\";HEX$(FLAG);
- 440 LOCATE 15,45: PRINT USING "\\"; HEX$((NOT FLAG)AND &HFF);
- 450 '------Highlite the word for the set bits--------------
- 460 LOCATE 8,2
- 470 FOR I = 7 TO 0 STEP -1
- 480 IF FNBITVALUE(FLAG,I) THEN BRITE = &HF ELSE BRITE = 7
- 490 COLOR BRITE: PRINT A$(I);", ";
- 500 NEXT
- 510 COLOR 7 'comment this out and find the sneaky bug.
- 520 IF INKEY$<>CHR$(27) THEN 370 'Esc to exit
- 530 '-------End of display loop--------------
- 540 CLS: POKE &H17,0 'Don't leave a mess in your nest.
- 550 GOSUB 630 ' enable CtrlBrk
- 560 END 'every prog should have one, that's spelled O-N-E.
- 570 '------------------------------------------
- 580 DATA Ins, CapsLock, NumLock, ScrollLock ,Alt, Ctrl, LeftShift, RightShift
- 590 'save CtrlBrk pointer and point to F000:FF53 dummy return in ROM
- 600 DEF SEG = 0: FOR I = 0 TO 3: POINTER%(I) = PEEK(108 + I) : NEXT
- 610 POKE 111,&HF0:POKE 110,0:POKE 109,&HFF:POKE 108,&H53:RETURN
- 620 'restore former CtrlBrk pointer
- 630 DEF SEG = 0: FOR I = 0 TO 3: POKE 108+I, POINTER%(I): NEXT: RETURN